
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>调试 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../libraries/guardian.html" />
    
    
    <link rel="prev" href="mnesia.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basics/basics.html">
            
                <a href="../basics/basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../basics/collections.html">
            
                <a href="../basics/collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../basics/enum.html">
            
                <a href="../basics/enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../basics/pattern-matching.html">
            
                <a href="../basics/pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../basics/control-structures.html">
            
                <a href="../basics/control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../basics/functions.html">
            
                <a href="../basics/functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../basics/pipe-operator.html">
            
                <a href="../basics/pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../basics/modules.html">
            
                <a href="../basics/modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../basics/mix.html">
            
                <a href="../basics/mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../basics/sigils.html">
            
                <a href="../basics/sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../basics/documentation.html">
            
                <a href="../basics/documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../basics/testing.html">
            
                <a href="../basics/testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../basics/comprehensions.html">
            
                <a href="../basics/comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../basics/strings.html">
            
                <a href="../basics/strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../basics/date-time.html">
            
                <a href="../basics/date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../basics/mix-tasks.html">
            
                <a href="../basics/mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../basics/iex-helpers.html">
            
                <a href="../basics/iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="plug.html">
            
                <a href="plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="eex.html">
            
                <a href="eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="ets.html">
            
                <a href="ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="mnesia.html">
            
                <a href="mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.5" data-path="debugging.html">
            
                <a href="debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >调试</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x81ED;&#x866B;&#xFF08;Bugs&#xFF09;&#x53EF;&#x8C13;&#x662F;&#x4EFB;&#x4F55;&#x9879;&#x76EE;&#x90FD;&#x65E0;&#x6CD5;&#x907F;&#x514D;&#x7684;&#x5B58;&#x5728;&#xFF0C;&#x6240;&#x4EE5;&#x8C03;&#x8BD5;&#x4E5F;&#x4E0D;&#x53EF;&#x6216;&#x7F3A;&#x3002;&#x672C;&#x8BFE;&#x7A0B;&#x6211;&#x4EEC;&#x5C06;&#x5B66;&#x4E60;&#x5982;&#x4F55;&#x8C03;&#x8BD5; Elixir &#x4EE3;&#x7801;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;&#x9759;&#x6001;&#x5206;&#x6790;&#x5DE5;&#x5177;&#x6765;&#x5E2E;&#x52A9;&#x5BFB;&#x627E;&#x53EF;&#x80FD;&#x5B58;&#x5728;&#x7684; bugs&#x3002;  </p>
<h2 id="dialyxir-&#x548C;-dialyzer">Dialyxir &#x548C; Dialyzer</h2>
<p><a href="http://erlang.org/doc/man/dialyzer.html" target="_blank">Dialyzer</a>&#xFF0C;&#x5168;&#x79F0;&#x5C31;&#x662F; <strong>DI</strong>screpancy <strong>A</strong>na<strong>LYZ</strong>er for <strong>ER</strong>lang&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x5DE5;&#x5177;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5B83;<em>&#x9605;&#x8BFB;</em>&#x548C;&#x5206;&#x6790;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;<em>&#x6267;&#x884C;</em>&#x5B83;&#x4EEC;&#xFF0C;&#x6BD4;&#x5982;&#x8BF4;&#xFF0C;&#x5BFB;&#x627E; bugs&#xFF0C;&#x65E0;&#x6CD5;&#x89E6;&#x53CA;&#x7684;&#x6B7B;&#x4EE3;&#x7801;&#x7B49;&#x3002;</p>
<p><a href="https://github.com/jeremyjh/dialyxir" target="_blank">Dialyxir</a> &#x5219;&#x662F;&#x5728; Elixir &#x91CC;&#x7B80;&#x5316;&#x4E86; Dialyzer &#x4F7F;&#x7528;&#x7684; mix &#x4EFB;&#x52A1;&#x3002;  </p>
<p>Specification &#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x50CF; Dialyzer &#x8FD9;&#x6837;&#x7684;&#x5DE5;&#x5177;&#x66F4;&#x597D;&#x5730;&#x7406;&#x89E3;&#x4EE3;&#x7801;&#x3002;&#x4E0D;&#x50CF;&#x90A3;&#x4E9B;&#x53EA;&#x80FD;&#x88AB;&#x4EBA;&#x7C7B;&#x9605;&#x8BFB;&#x548C;&#x7406;&#x89E3;&#x7684;&#x6587;&#x6863;&#xFF08;&#x5047;&#x5982;&#x5B58;&#x5728;&#x6216;&#x8005;&#x5199;&#x7684;&#x8DB3;&#x591F;&#x597D;&#x7684;&#x8BDD;&#xFF09;&#xFF0C;<code>@spec</code> &#x4F7F;&#x7528;&#x4E86;&#x4E00;&#x4E9B;&#x53EF;&#x4EE5;&#x88AB;&#x673A;&#x5668;&#x7406;&#x89E3;&#x7684;&#xFF0C;&#x66F4;&#x89C4;&#x8303;&#x7684;&#x8BED;&#x6CD5;&#x3002;  </p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x628A; Dialyxir &#x52A0;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x91CC;&#x5934;&#x5427;&#x3002;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F;&#x5C31;&#x662F;&#x6DFB;&#x52A0;&#x4F9D;&#x8D56;&#x5230; <code>mix.exs</code> &#x6587;&#x4EF6;&#x4E2D;&#xFF1A;  </p>
<pre><code class="lang-elixir"><span class="hljs-function"><span class="hljs-keyword">defp</span> <span class="hljs-title">deps</span></span> <span class="hljs-keyword">do</span>
  [{<span class="hljs-symbol">:dialyxir</span>, <span class="hljs-string">&quot;~&gt; 0.4&quot;</span>, <span class="hljs-symbol">only:</span> [<span class="hljs-symbol">:dev</span>]}]
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x7136;&#x540E;&#x8C03;&#x7528;&#x4E00;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#xFF1A;  </p>
<pre><code class="lang-shell">$ mix deps.get
...
$ mix deps.compile
</code></pre>
<p>&#x7B2C;&#x4E00;&#x4E2A;&#x547D;&#x4EE4;&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5; Dialyxir&#x3002;&#x6216;&#x8BB8;&#x4F60;&#x4F1A;&#x540C;&#x65F6;&#x88AB;&#x8981;&#x6C42;&#x5B89;&#x88C5; Hex&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x547D;&#x4EE4;&#x7F16;&#x8BD1; Dialyxir &#x5E94;&#x7528;&#x3002;&#x5982;&#x679C;&#x4F60;&#x60F3;&#x5168;&#x5C40;&#x5B89;&#x88C5; Dialyxir&#xFF0C;&#x8BF7;&#x53C2;&#x8003;&#x5B83;&#x7684;<a href="https://github.com/jeremyjh/dialyxir#installation" target="_blank">&#x6587;&#x6863;</a>&#x3002;  </p>
<p>&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x6B65;&#x9AA4;&#x5C31;&#x662F;&#x8981;&#x8FD0;&#x884C; Dialyzer &#x6765;&#x91CD;&#x5EFA; PLT&#xFF08;Persistent Lookup Table&#xFF09;&#x3002;&#x6BCF;&#x6B21;&#x5B89;&#x88C5;&#x65B0;&#x7248;&#x672C;&#x7684; Erlang &#x6216;&#x8005; Elixir &#x540E;&#xFF0C;&#x4F60;&#x90FD;&#x8981;&#x505A;&#x8FD9;&#x4E00;&#x6B65;&#x3002;&#x5E78;&#x8FD0;&#x5730;&#x662F;&#xFF0C;Dialyzer &#x4E0D;&#x4F1A;&#x6BCF;&#x6B21;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#x90FD;&#x53BB;&#x5206;&#x6790;&#x6807;&#x51C6;&#x7A0B;&#x5E8F;&#x5E93;&#x3002;&#x8FD9;&#x4E2A;&#x91CD;&#x5EFA;&#x8FC7;&#x7A0B;&#x9700;&#x8981;&#x597D;&#x51E0;&#x5206;&#x949F;&#x624D;&#x80FD;&#x4E0B;&#x8F7D;&#x5B8C;&#x6210;&#x3002;  </p>
<pre><code class="lang-shell">$ mix dialyzer --plt
Starting PLT Core Build ... this will take awhile
dialyzer --build_plt --output_plt /.dialyxir_core_18_1.3.2.plt --apps erts kernel stdlib crypto public_key -r /Elixir/lib/elixir/../eex/ebin /Elixir/lib/elixir/../elixir/ebin /Elixir/lib/elixir/../ex_unit/ebin /Elixir/lib/elixir/../iex/ebin /Elixir/lib/elixir/../logger/ebin /Elixir/lib/elixir/../mix/ebin
  Creating PLT /.dialyxir_core_18_1.3.2.plt ...
...
 done in 5m14.67s
done (warnings were emitted)
</code></pre>
<h2 id="&#x4EE3;&#x7801;&#x9759;&#x6001;&#x5206;&#x6790;">&#x4EE3;&#x7801;&#x9759;&#x6001;&#x5206;&#x6790;</h2>
<p>Dialyxir &#x5DF2;&#x7ECF;&#x51C6;&#x5907;&#x597D;&#x4E86;&#xFF1A;  </p>
<pre><code class="lang-shell">$ mix dialyzer
...
examples.ex:3: Invalid type specification for function &apos;Elixir.Examples&apos;:sum_times/1. The success typing is (_) -&gt; number()
...
</code></pre>
<p>Dialyzer &#x63D0;&#x793A;&#x7684;&#x4FE1;&#x606F;&#x5DF2;&#x7ECF;&#x5F88;&#x660E;&#x786E;&#x4E86;&#xFF1A;&#x51FD;&#x6570; <code>sum_times/1</code> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x548C;&#x58F0;&#x660E;&#x7684;&#x4E0D;&#x4E00;&#x6837;&#x3002;&#x56E0;&#x4E3A; <code>Enum.sum/1</code> &#x8FD4;&#x56DE;&#x7684;&#x662F; <code>number</code> &#x800C;&#x4E0D;&#x662F;&#x4E00;&#x4E2A; <code>integer</code>&#x3002;&#x4F46;&#x662F; <code>sum_times/1</code> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#x58F0;&#x660E;&#x4E3A; <code>integer</code>&#x3002;  </p>
<p>&#x56E0;&#x4E3A; <code>number</code> &#x5E76;&#x4E0D;&#x662F; <code>integer</code>&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5C31;&#x5F97;&#x5230;&#x4E86;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;&#x90A3;&#x8BE5;&#x600E;&#x4E48;&#x4FEE;&#x6539;&#xFF1F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>round/1</code> &#x51FD;&#x6570;&#x628A; <code>number</code> &#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x4E3A; <code>integer</code>&#xFF1A;  </p>
<pre><code class="lang-elixir"><span class="hljs-variable">@spec</span> sum_times(integer) <span class="hljs-symbol">:</span><span class="hljs-symbol">:</span> integer
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sum_times</span></span>(a) <span class="hljs-keyword">do</span>
  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
  |&gt; Enum.map(<span class="hljs-keyword">fn</span> el -&gt; el * a <span class="hljs-keyword">end</span>)
  |&gt; Enum.sum()
  |&gt; round
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6700;&#x540E;&#xFF1A;  </p>
<pre><code class="lang-shell">$ mix dialyzer
...
  Proceeding with analysis... done in 0m0.95s
done (passed successfully)
</code></pre>
<p>&#x501F;&#x52A9; specifications &#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x8FDB;&#x884C;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5206;&#x6790;&#xFF0C;&#x5E76;&#x8BA9;&#x4EE3;&#x7801;&#x53D8;&#x5F97;&#x66F4;&#x5065;&#x58EE;&#x548C;&#x5305;&#x542B;&#x66F4;&#x5C11;&#x7684; bugs&#x3002;  </p>
<h2 id="&#x8C03;&#x8BD5;">&#x8C03;&#x8BD5;</h2>
<p>&#x6709;&#x65F6;&#xFF0C;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x662F;&#x4E0D;&#x591F;&#x7684;&#x3002;&#x8981;&#x627E;&#x5230; bugs&#xFF0C;&#x7406;&#x89E3;&#x4EE3;&#x7801;&#x7684;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6848;&#x53D1;&#x5C31;&#x662F;&#x5728;&#x4EE3;&#x7801;&#x91CC;&#x52A0;&#x4E0A;&#x8BF8;&#x5982; <code>IO.puts/2</code> &#x8FD9;&#x6837;&#x7684;&#x4EE3;&#x7801;&#x6765;&#x6253;&#x5370;&#x8F93;&#x51FA;&#x4E00;&#x4E9B;&#x8BED;&#x53E5;&#x4EE5;&#x4FBF;&#x8DDF;&#x8E2A;&#x503C;&#x7684;&#x53D8;&#x5316;&#x548C;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x6837;&#x7684;&#x624B;&#x6BB5;&#x975E;&#x5E38;&#x7684;&#x539F;&#x59CB;&#xFF0C;&#x5E76;&#x6709;&#x5F88;&#x591A;&#x5C40;&#x9650;&#x6027;&#x3002;&#x5E86;&#x5E78;&#x7684;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Erlang &#x7684;&#x8C03;&#x8BD5;&#x5668;&#x6765;&#x8C03;&#x8BD5; Elixir &#x4EE3;&#x7801;&#x3002;  </p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x7684;&#x6A21;&#x5757;&#xFF1A;  </p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">cpu_burns</span></span>(a, b, c) <span class="hljs-keyword">do</span>
    x = a * <span class="hljs-number">2</span>
    y = b * <span class="hljs-number">3</span>
    z = c * <span class="hljs-number">5</span>

    x + y + z
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x7136;&#x540E;&#x8FD0;&#x884C; <code>iex</code>&#xFF1A;  </p>
<pre><code class="lang-bash">$ iex -S mix
</code></pre>
<p>&#x518D;&#x8FD0;&#x884C;&#x8C03;&#x8BD5;&#x5668;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; <span class="hljs-symbol">:debugger</span>.start()
{<span class="hljs-symbol">:ok</span>, <span class="hljs-comment">#PID&lt;0.307.0&gt;}</span>
</code></pre>
<p>Erlang &#x7684; <code>:debugger</code> &#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x8BBF;&#x95EE;&#x8C03;&#x8BD5;&#x5668;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>start/1</code> &#x51FD;&#x6570;&#x6765;&#x5BF9;&#x5B83;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF1A;  </p>
<ul>
<li>&#x901A;&#x8FC7;&#x4F20;&#x5165;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#x6765;&#x6307;&#x5B9A;&#x5916;&#x90E8;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;  </li>
<li>&#x5982;&#x679C;&#x53C2;&#x6570;&#x662F; <code>:local</code> &#x6216;&#x8005; <code>:global</code>&#xFF0C;&#x8C03;&#x8BD5;&#x5668;&#x5C31;&#x4F1A;&#xFF1A;  <ul>
<li><code>:global</code> - &#x8C03;&#x8BD5;&#x5668;&#x4F1A;&#x89E3;&#x6790;&#x6240;&#x6709;&#x5DF2;&#x77E5;&#x8282;&#x70B9;&#x7684;&#x4EE3;&#x7801;&#x3002;&#x8FD9;&#x4E2A;&#x662F;&#x9009;&#x9879;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x3002;  </li>
<li><code>:local</code> - &#x8C03;&#x8BD5;&#x5668;&#x53EA;&#x4F1A;&#x89E3;&#x6790;&#x5F53;&#x524D;&#x8282;&#x70B9;&#x7684;&#x4EE3;&#x7801;&#x3002;  </li>
</ul>
</li>
</ul>
<p>&#x4E0B;&#x4E00;&#x6B65;&#x5C31;&#x662F;&#x628A;&#x8C03;&#x8BD5;&#x5668;&#x6302;&#x8F7D;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x6A21;&#x5757;&#x4E0A;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; <span class="hljs-symbol">:int</span>.ni(Example)
{<span class="hljs-symbol">:module</span>, Example}
</code></pre>
<p><code>:int</code> &#x6A21;&#x5757;&#x662F;&#x4E00;&#x4E2A;&#x89E3;&#x6790;&#x5668;&#x3002;&#x5B83;&#x80FD;&#x8BA9;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x65AD;&#x70B9;&#xFF0C;&#x548C;&#x4E00;&#x6B65;&#x6B65;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x3002;  </p>
<p>&#x5F53;&#x4F60;&#x6253;&#x5F00;&#x8C03;&#x8BD5;&#x5668;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x51FA;&#x73B0;&#x7C7B;&#x4F3C;&#x7684;&#x65B0;&#x7A97;&#x53E3;&#xFF1A;  </p>
<p><img src="../../images/debugger_1.png" alt="Debugger Screenshot 1"></p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x628A;&#x8C03;&#x8BD5;&#x5668;&#x6302;&#x8F7D;&#x5230;&#x8981;&#x8C03;&#x8BD5;&#x7684;&#x6A21;&#x5757;&#x65F6;&#xFF0C;&#x5B83;&#x5C31;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x5DE6;&#x8FB9;&#x7684;&#x83DC;&#x5355;&#xFF1A;  </p>
<p><img src="../../images/debugger_2.png" alt="Debugger Screenshot 2"></p>
<h3 id="&#x521B;&#x5EFA;&#x65AD;&#x70B9;">&#x521B;&#x5EFA;&#x65AD;&#x70B9;</h3>
<p>&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#x5C31;&#x662F;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x5230;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x540E;&#xFF0C;&#x4F1A;&#x6302;&#x8D77;&#x7684;&#x5730;&#x65B9;&#x3002;&#x6709;&#x4E24;&#x79CD;&#x521B;&#x5EFA;&#x65AD;&#x70B9;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;  </p>
<ul>
<li>&#x5728;&#x4EE3;&#x7801;&#x91CC;&#x8C03;&#x7528; <code>:int.break/2</code>  </li>
<li>&#x901A;&#x8FC7;&#x8C03;&#x8BD5;&#x5668;&#x754C;&#x9762;</li>
</ul>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x5148;&#x5728; IEx &#x5C1D;&#x8BD5;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; <span class="hljs-symbol">:int</span>.<span class="hljs-keyword">break</span>(Example, <span class="hljs-number">8</span>)
<span class="hljs-symbol">:ok</span>
</code></pre>
<p>&#x8FD9;&#x5728; <code>Example</code> &#x6A21;&#x5757;&#x4EE3;&#x7801;&#x7684;&#x7B2C; 8 &#x884C;&#x5904;&#x8BBE;&#x5B9A;&#x4E86;&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#x3002;&#x7136;&#x540E;&#x5F00;&#x59CB;&#x8C03;&#x7528;&#x6211;&#x4EEC;&#x7684;&#x51FD;&#x6570;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; Example.cpu_burns(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>)
</code></pre>
<p>&#x5728; IEx &#x4E2D;&#xFF0C;&#x4EE3;&#x7801;&#x7684;&#x8FD0;&#x884C;&#x88AB;&#x6302;&#x8D77;&#x4E86;&#xFF0C;&#x8C03;&#x8BD5;&#x5668;&#x7A97;&#x53E3;&#x663E;&#x793A;&#x5982;&#x4E0B;&#xFF1A;  </p>
<p><img src="../../images/debugger_3.png" alt="Debugger Screenshot 3"></p>
<p>&#x53E6;&#x4E00;&#x4E2A;&#x7A97;&#x53E3;&#x4F1A;&#x663E;&#x793A;&#x51FA;&#x5F53;&#x524D;&#x6267;&#x884C;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#xFF1A;  </p>
<p><img src="../../images/debugger_4.png" alt="Debugger Screenshot 4"></p>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x7A97;&#x53E3;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x67E5;&#x770B;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;&#x8DF3;&#x5230;&#x4E0B;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x6216;&#x8005;&#x6267;&#x884C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x8C03;&#x7528; <code>:int.disable_break/2</code> &#x5C31;&#x80FD;&#x591F;&#x7981;&#x7528;&#x65AD;&#x70B9;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; <span class="hljs-symbol">:int</span>.disable_break(Example, <span class="hljs-number">8</span>)
<span class="hljs-symbol">:ok</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8C03;&#x7528; <code>:int.enable_break/2</code> &#x6765;&#x91CD;&#x65B0;&#x5F00;&#x542F;&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#xFF0C;&#x6216;&#x8005;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x5220;&#x9664;&#x65AD;&#x70B9;&#xFF1A;  </p>
<pre><code class="lang-elixir">iex &gt; <span class="hljs-symbol">:int</span>.delete_break(Example, <span class="hljs-number">8</span>)
<span class="hljs-symbol">:ok</span>
</code></pre>
<p>&#x5728;&#x8C03;&#x8BD5;&#x5668;&#x7A97;&#x53E3;&#x4E5F;&#x6709;&#x540C;&#x6837;&#x7684;&#x64CD;&#x4F5C;&#x9009;&#x9879;&#x3002;&#x5728;&#x9876;&#x5C42;&#x83DC;&#x5355;&#xFF0C;<strong>Break</strong>&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x9009;&#x62E9; <strong>Line Break</strong> &#x5E76;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x9009;&#x62E9;&#x4E86;&#x4E00;&#x884C;&#x6CA1;&#x6709;&#x4EE3;&#x7801;&#x7684;&#x6DA4;&#x70E6;&#x8BBE;&#x7F6E;&#x4E86;&#x65AD;&#x70B9;&#xFF0C;&#x5B83;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#xFF0C;&#x4F46;&#x662F;&#x4F9D;&#x7136;&#x4F1A;&#x5728;&#x8C03;&#x8BD5;&#x5668;&#x7A97;&#x53E3;&#x51FA;&#x73B0;&#x3002;&#x65AD;&#x70B9;&#x7684;&#x7C7B;&#x578B;&#x6709;&#x4E09;&#x79CD;&#xFF1A;  </p>
<ul>
<li>&#x884C;&#x65AD;&#x70B9; - &#x8C03;&#x8BD5;&#x5668;&#x5230;&#x8FBE;&#x76EE;&#x6807;&#x884C;&#x65F6;&#xFF0C;&#x6302;&#x8D77;&#x6267;&#x884C;&#x3002;&#x8FD9;&#x79CD;&#x65AD;&#x70B9;&#x901A;&#x8FC7; <code>:int.break/2</code> &#x8BBE;&#x7F6E;&#x3002;  </li>
<li>&#x6761;&#x4EF6;&#x65AD;&#x70B9; - &#x548C;&#x884C;&#x65AD;&#x70B9;&#x7C7B;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x8C03;&#x8BD5;&#x5668;&#x53EA;&#x6709;&#x5728;&#x6EE1;&#x8DB3;&#x7279;&#x5B9A;&#x6761;&#x4EF6;&#x7684;&#x65F6;&#x5019;&#x624D;&#x4F1A;&#x6302;&#x8D77;&#x4EE3;&#x7801;&#x3002;<code>:int.get_binding/2</code> &#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x7ED1;&#x5B9A;&#x7684;&#x6761;&#x4EF6;&#x53D8;&#x91CF;&#x3002;  </li>
<li>&#x51FD;&#x6570;&#x65AD;&#x70B9; - &#x8C03;&#x8BD5;&#x5668;&#x4F1A;&#x5728;&#x51FD;&#x6570;&#x7684;&#x7B2C;&#x4E00;&#x884C;&#x6302;&#x8D77;&#x3002;&#x8FD9;&#x79CD;&#x65AD;&#x70B9;&#x901A;&#x8FC7; <code>:int.break_in/3</code> &#x914D;&#x7F6E;&#x3002;  </li>
</ul>
<p>&#x51C6;&#x5907;&#x5C31;&#x7EEA;&#xFF01;&#x8C03;&#x8BD5;&#x5FEB;&#x4E50;&#xFF01;  </p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mnesia.html" class="navigation navigation-prev " aria-label="Previous page: Mnesia 数据库">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../libraries/guardian.html" class="navigation navigation-next " aria-label="Next page: Guardian(基础)">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.0.1","title":"调试","level":"4.5","depth":1,"next":{"title":"Guardian(基础)","level":"5.1","depth":1,"path":"lessons/libraries/guardian.md","ref":"lessons/libraries/guardian.md","articles":[]},"previous":{"title":"Mnesia 数据库","level":"4.4","depth":1,"path":"lessons/specifics/mnesia.md","ref":"lessons/specifics/mnesia.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/specifics/debugging.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

